<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @onSelectChange="selectChange" @search="search"></searchData>
        <a-card>
            <!-- <title-name title="年度会议计划"></title-name> -->
            <!-- <div class="table-operator">
                
            </div> -->
            <a-spin :spinning="spinning">
                <list-table
                  ref="table"
                  row-key="id"
                  :columns="columns"
                  :request="loadData"
                  :alert="true"
                  show-size-changer
                  show-quick-jumper
                >
                  <a-button type="primary" slot="prefix" v-btnPermission="'oa_005_add_01'" @click="showAddModal">发起会议计划编制</a-button>
                  <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
                  <span slot="status" slot-scope="text">
                      <list-status :status="text"></list-status>
                  </span>
                  <span slot="operation" slot-scope="text, record">
                    <!-- 
                    1）办公室：发起会议计划编制、查看、编辑、审批信息、发布
                    2）其他参与会议编制的部门：查看、编辑、审批信息
                    3）领导：查看 
                    -->
                      <MoreButton>
                    <template>
                        <a @click="handleUpdate('look', record)">查看</a>
                    </template>
                    <span v-if="(record.permissions !== 3) &&
                          (record.planStatus == 'WRITING' || record.planStatus == 'REJECTED') &&
                          (record.deptEdit !== 1)"
                          v-btnPermission="'oa_005_edi_02'"
                    >
                        <a @click="handleUpdate('edit', record)">编辑</a>
                    </span>
                    <span v-if="(record.permissions !== 3) && (record.planStatus !== 'WRITING')">
                        <approval-button
                            :id="record.id"
                            text="审批信息"
                        ></approval-button>
                    </span>
                    <span v-if="(record.permissions == 1) && (record.planStatus == 'PAST')" v-btnPermission="'oa_005_rel_03'">
                        <a @click="handleUpdate('release', record)">发布</a>
                    </span>
                          </MoreButton>
                  </span>
              </list-table>
            </a-spin>
        </a-card>
        
        <!-- add modal start -->
        <AddAnnualConference
          :visible="addModalVisible"
          @cancelSub="hideAddModal"
          @submitForm="showAddModal"
        ></AddAnnualConference>
        <!-- add modal end -->
    </base-breadcrumb>
</template>
<script>
// import { STable } from '@/components'
import listStatus from './components/listStatus.vue'
import AddAnnualConference from './add.vue'
import { annualPlanList, annualPlanSchedulesEdit } from '@/api/office/anualConference/index'
import anualConBase from './baseconfig.js'
export default {
  name:'a'+Date.now(),
  components: {
        // STable,
        listStatus,
        AddAnnualConference
    },
    data() {
        this.columns = anualConBase.columns
        this.searchArr = anualConBase.searchArr
        return {
            queryParam: {
              query: {}
            },
            first: true,
            addModalVisible: false,
            spinning: false,
            loadData: async (parameter) => {
              const requestParameters = Object.assign({}, parameter, this.queryParam)
              return annualPlanList(requestParameters).then(res => {
                return res;
              })
              // try {
              //   const requestParameters = Object.assign({}, parameter, this.queryParam)
              //   this.spinning = true;
              //   const res = await annualPlanList(requestParameters);
              //   this.spinning = false;
              //   return Promise.resolve({
              //     data: res.data || [],
              //     currentPage: res.currentPage || parameter.pageNo,
              //     totalSize: res.totalSize || 0,
              //   })
              // } catch (e) {
              //   this.spinning = false;
              //   return Promise.reject(e)
              // }
            },
        }
    },
    computed: {
      userLevel() {
        const res = 'office';
        // const res = 'other';
        // const res = 'leader';
        return res;
      }
    },
    mounted() {
    },
    methods: {
        selectChange(val) {
          if (this.first){
            this.search({unitId: val.id});
            this.first = false;
          }
        },
        //搜索
        search(val = {}) {
            this.queryParam.query = {
                ...val,
            }

            this.$refs.table.refresh(true)
        },
        handleUpdate(type, data = {}) {
          if (type == 'add') {
            this.showAddModal()
          } else if (type == 'edit' || type == 'look') {
            const name = (type == 'edit') ? 'AnnualConferenceEdit' : 'AnnualConferenceDetail';
            this.$router.push({
                name: name,
                query: {
                    id: data.id || '',
                    pageType: type,
                    status: data.planStatus,
                    permissions: data.permissions,
                    year: data.year
                },
            })
          } else if (type == 'release') {
            this.onRelease(data.id)
          }
        },
        showAddModal() {
          this.addModalVisible = true;
        },
        hideAddModal(refresh) {
          this.addModalVisible = false;
          if (refresh == 'refresh') this.$refs.table.refresh(true)
        },
        onRelease(id) {
          const param = {
            id: id,
            planStatus: 'PUBLISHED'
          }
          this.spinning = true;
          annualPlanSchedulesEdit(param).then((res) => {
            this.spinning = false;
            this.$refs.table.refresh()
            if ((res && res.data && res.data.code) || (res && res.code == 200)) {
              this.$message.success('发布成功');
            } else {
              this.$message.error('发布失败！');
            }
          }).catch(() => {
            this.spinning = false;
          })
        },

    },
}
</script>
<style>
  .flex-model-form .ant-form-item{
    display: flex;
  }
  .ant-select-dropdown-menu {
    text-align: left;
  }
</style>
